import React, { Component } from 'react'
import ReactDOM from 'react-dom/client'
import './index.css'
import Tabs from './components/Tabs'
import Form from './components/Form'
import List from './components/List'

export default class App extends Component {
  state = {
    // hot: 热度排序  time: 时间排序
    tabs: [
      {
        id: 1,
        name: '热度',
        type: 'hot',
      },
      {
        id: 2,
        name: '时间',
        type: 'time',
      },
    ],
    active: 'time', // 高亮的 type
    list: [
      {
        id: 1,
        author: '刘德华',
        comment: '给我一杯忘情水',
        // !把时间转成日期对象
        time: new Date('2021-12-10 09:09:00'),
        img: 'https://y.qq.com/music/photo_new/T001R300x300M000003aQYLo2x8izP.jpg?max_age=2592000',
        // 1: 点赞 0：无态度 -1:踩
        attitude: 1,
        hot: 888,
      },
      {
        id: 2,
        author: '周杰伦',
        comment: '听妈妈的话',
        time: new Date('2022-8-11 09:09:00'),
        img: 'https://y.qq.com/music/photo_new/T001R500x500M0000025NhlN2yWrP4.jpg?max_age=2592000',
        // 1: 点赞 0：无态度 -1:踩
        attitude: 0,
        hot: 999,
      },
      {
        id: 3,
        author: '陈奕迅',
        comment: '十年',
        time: new Date('2022-12-11 10:09:00'),
        img: 'https://y.qq.com/music/photo_new/T001R500x500M000003Nz2So3XXYek.jpg?max_age=2592000',
        // 1: 点赞 0：无态度 -1:踩
        attitude: -1,
        hot: 66,
      },
    ],
  }
  // !#1 父组件准备一个方法并传递给子组件
  changeActive = (active) => {
    // !#3 父组件接收参数并做修改
    this.setState({ active })
  }
  render() {
    const { tabs, active, list } = this.state
    return (
      <div className='App'>
        <div className='comment-container'>
          <div className='comment-head'>
            <span>{list.length} 评论</span>
          </div>
          {/* Tabs */}
          <Tabs tabs={tabs} active={active} changeActive={this.changeActive} />
          {/* Form */}
          <Form />
          {/* List */}
          {/* //!#0 传递 active */}
          <List list={list} active={active} />
        </div>
      </div>
    )
  }
}

ReactDOM.createRoot(document.querySelector('#root')).render(<App />)
